<template>

<!--
    tag="a"
    target="_blank"
    :href="link" -->
  <q-item
    clickable
    :to="isLinkExternal?undefined:link"
    :tag="isLinkExternal?'a':undefined"
    :target="isLinkExternal?'_blank':undefined"
    :href="isLinkExternal?link:undefined"
  >
    <q-item-section
      v-if="icon"
      avatar
    >
      <q-icon :name="icon" />
    </q-item-section>

    <q-item-section>
      <q-item-label>{{ title }}</q-item-label>
      <q-item-label caption>
        {{ caption }}
      </q-item-label>
    </q-item-section>
  </q-item>
</template>

<script>
export default {
  name: 'EssentialLink',
  data () {
    return {}
  },
  computed: {
    isLinkExternal: function () {
      return this.link && (this.link.startsWith('http://') || this.link.startsWith('https://'))
    }
  },
  props: {
    title: {
      type: String,
      required: true
    },

    caption: {
      type: String,
      default: ''
    },

    link: {
      type: String,
      default: '#'
    },

    icon: {
      type: String,
      default: ''
    }
  }
}
</script>
